package com.sailors.common.task.provider.infra.system.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger config
 *
 * @description: swageer配置
 * @author: cyj
 * @date 2022 -11-22 14:06:39
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Value("${spring.profiles.active}")
    private String profile;

    @Value("${spring.application.name}")
    private String appName;

    /**
     * 接口文档地址 swagger-ui http://192.168.100.47:8080/swagger-ui.html
     * knife4j http://192.168.100.47:8080/doc.html#/home
     * @return
     */
    @Bean
    public Docket api() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .enable(!profile.contains("prod"))
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.hisailors.bd.crm.provider"))
//                .apis(RequestHandlerSelectors.any())
//                .build();

        return new Docket(DocumentationType.SWAGGER_2)
                .enable(!profile.contains("prod"))
                .pathMapping("/")
                .select()
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title(appName)
                        .description(appName + "-> 接口文档")
                        .version("1.0")
                        .build());
    }
}
